<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
   return $request->user();
});


Route::namespace('Api')->group(function () {
   //JWT认证
   Route::middleware('jwt.auth')->group(function () {

   });
   //首页
   Route::get('home', 'HomeController@index')->name('home.index');
   //用户中心
   Route::resource('users', 'UserController');
   //账户管理
   Route::resource('accounts', 'AccountController');
   //地址管理
   Route::post('address/default_address', 'AddressController@default_address')->name('address.default_address'); //默认地址
   Route::resource('addresses', 'AddressController')->except('create', 'edit');
   //购物车管理
   Route::patch('cart/change_num', 'CartController@change_num')->name('cart.change_num'); //改变数量
   Route::resource('carts', 'CartController')->only('index', 'store', 'destroy');
   //订单管理
   Route::post('order/checkout', 'OrderController@checkout')->name('order.checkout'); //结算
   Route::resource('orders', 'OrderController')->except('create', 'edit', 'update');
   //订单支付
   Route::prefix('pay')->group(function () {
      Route::post('alipay', 'PayController@alipay')->name('pay.alipay');  //支付宝支付
      Route::post('return', 'PayController@return')->name('pay.return');  //支付宝通知
      Route::post('wechat', 'PayController@wechat')->name('pay.wechat');  //微信小程序支付
      Route::post('wechat_mp', 'PayController@wechat_mp')->name('pay.wechat_mp');  //微信JSSDK支付
   });

   Route::any('/auth', 'TokenController@auth');   //获取token
   Route::get('/get_openid', 'TokenController@get_openid');  //获取openid
   Route::post('pay/alipay_notify', 'PayController@alipay_notify')->name('pay.alipay_notify');  //支付宝回调,不能过jwt中间件
   Route::post('pay/wechat_notify', 'PayController@wechat_notify')->name('pay.wechat_notify');  //微信回调,不能过jwt中间件

});
